package com.hliushi.learn.bean;

import com.hliushi.learn.annotation.valid.Email;
import com.hliushi.learn.annotation.valid.Phone;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

/**
 * @author llhuang10
 */
@Entity
@Table(name = "person")
@Data
@AllArgsConstructor
@NoArgsConstructor
@GenericGenerator(name = "jpa-uuid", strategy = "uuid")
public class Person {


    /**
     * bug 点
     * .@Id
     * .@GeneratedValue(strategy = GenerationType.IDENTITY)
     * private String classId;
     * <p>
     * 报错信息: hibernate CommandAcceptanceException: Error executing DDL
     * .            Incorrect column specifier for column 'class_id'
     * # 无法为String字符串类型使用主键自增策略
     */
    @Id
    @GeneratedValue(generator = "jpa-uuid")
    @Column(length = 32)
    @NotNull(message = "personId 不能为空")
    private String personId;

    @Column(unique = true)
    @Size(max = 40)
    @NotNull(message = "name 不能为空")
    private String name;

    @Pattern(regexp = "((^Man$|^Women$|^UGM$))", message = "sex 值不在可选范围内")
    @NotNull(message = "sex 不能为空")
    private String sex;

    @Email(message = "email 格式不正确")
    @NotNull(message = "email 不能为空")
    private String email;

    @Phone
    private String phone;
}
